/**      
 * @file		passingParameters.cpp
 * @description		This example shows how to pass parameters by
 *			value, by reference with reference pointers, and
 *			by reference with pointer parameters.	
 * @course		CSCI 123 Section 00000
 * @assignment 
 * @date		mm/dd/yyyy
 * @author		Brad Rippe (00000000) brippe@fullcoll.edu
 * @version		1.0
 */
#include <iostream>
using namespace std;

/**
 * Simple demonstration of pass by value parameters
 * the arguments (p1, p2) values are copied and placed
 * on the call stack. Any manipulation to those values
 * is popped off the stack once the function returns
 * @param aP1 the first parameter
 * @param aP2 the second parameter
 */
void passByValue(int aP1, int aP2);

/**
 * Simple demonstration of pass by reference with reference parameters.
 * the arguments (p1, p2) memory addresses are given to the function.
 * No copying of data occurs. Any manipulation that takes place in the
 * function, modifies the arguments passed to the function
 * @param aP1 the first parameter
 * @param aP2 the second parameter
 */
void passByRefWithRefArgs(int& aP1, int& aP2);

/**
 * Simple demonstration of pass by reference with pointer parameters.
 * the arguments (p1, p2) memory addresses are given to the function.
 * Since aP1 and aP2 are pointers they must point to memory addresses
 * thus the reason we send &p1, &p2 to the function. Pointers point to 
 * memory addresses.
 * Again no copying of data occurs. Any manipulation that takes place in the
 * function, modifies the arguments passed to the function
 * @param aP1 the first parameter
 * @param aP2 the second parameter
 */
void passByRefWithPtrArgs(int *aP1, int *aP2);

/**
 * @return zero if the application executes successfully
 */
int main() {
	int p1 = 44;
	int p2 = 22;
	
	// send the values to the function
	passByValue(p1, p2);
	passByRefWithRefArgs(p1, p2);
	// &p1 returns the memory address of p1
	passByRefWithPtrArgs(&p1, &p2);

	return 0;
}

void passByValue(int aP1, int aP2) {
	cout << "Call by Value parameters\n";
	cout << "The parameters are popped off the stack when the call returns\n";
	cout << "aP1 == " << aP1 << endl;
	cout << "aP2 == " << aP2 << endl << endl;
}

void passByRefWithRefArgs(int& aP1, int& aP2) {
	cout << "Call by Reference with reference parameters\n";
	cout << "The parameters point to the arguments address and are not copied";
	cout << " onto the call stack.\n";
	cout << "aP1 == " << aP1 << endl;
	cout << "aP2 == " << aP2 << endl << endl;
}

void passByRefWithPtrArgs(int *aP1, int *aP2){
	cout << "Call by Reference with pointer parameters\n";
	cout << "The parameters point to the arguments address and are not copied";
	cout << " onto the call stack.\n";
	cout << "aP1 == " << *aP1 << endl;
	cout << "aP2 == " << *aP2 << endl << endl;
}
